package com.xin.chaingeneration.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xin.chaingeneration.entity.ProductType;
import com.xin.chaingeneration.mapper.ProductTypeMapper;
import com.xin.chaingeneration.service.ProductTypeService;
import org.springframework.stereotype.Service;

@Service
public class ProductTypeServiceImpl extends ServiceImpl<ProductTypeMapper, ProductType> implements ProductTypeService {

    @Override
    public boolean existsByTypeName(String typeName) {
        // 获取ProductTypeMapper的实例
        ProductTypeMapper productTypeMapper = this.baseMapper;

        // 构建查询条件
        QueryWrapper<ProductType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("type_name", typeName); // 假设数据库中对应字段是type_name

        // 查询并返回是否存在
        int count = productTypeMapper.selectCount(queryWrapper);
        return count > 0;
    }

}
